package co.eam.edu.proyecto_final_empresa.web.seguridad;

import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Filter implementation class SesionFilter
 */
@WebFilter(dispatcherTypes = {
				DispatcherType.REQUEST, 
				DispatcherType.FORWARD, 
				DispatcherType.INCLUDE, 
				DispatcherType.ERROR
		}
					, urlPatterns = { "/secured/*" })
public class SesionFilter implements Filter {

    /**
     * Default constructor. 
     */
    public SesionFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	    
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest) request;
//	    SesionBean sesion= (SesionBean) req.getSession().getAttribute("sesionBean");
//	    
//	    //si no hay sesion, redirecciona a inicio..
//	    if(sesion!=null && !sesion.haySesion()){
//	       HttpServletResponse resp=(HttpServletResponse) response; 
//	    // URL base del proyecto.
//	        String urlBase = request.getServletContext().getContextPath();
//	        resp.sendRedirect(urlBase+"/index.jsf?faces-redirect=true");
//	       
//	    }
	    
	    
	    
	    
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
